package com.xy.tianyu.module.novel.fragment

import android.graphics.Color
import android.util.TypedValue
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.blankj.utilcode.util.BarUtils
import com.google.android.material.tabs.TabLayout
import com.xy.tianyu.LazyLoadBaseFragment
import com.xy.tianyu.R
import com.xy.tianyu.module.novel.adapter.CompetitivePagerAdapter
import kotlinx.android.synthetic.main.fragment_book_competitive.*


/**
 * @time 2020/10/27 16:12
 * @class 描述:精品
 */
class BookCompetitiveFragment : LazyLoadBaseFragment(){
    private var titles = mutableListOf<String>()
    private var fragments = mutableListOf<Fragment>()
    private var selectColor = "#FFA428"
    private var normalColor = "#000000"
    private var whiteColor = "#ffffff"
    private var topBgColor = "#FF900C"
    override fun setContentView(): Int {
        return R.layout.fragment_book_competitive
    }

    override fun lazyLoad() {

        titles.add(getString(R.string.ty_book_recommend))
        titles.add(getString(R.string.ty_book_man))
        titles.add(getString(R.string.ty_book_woman))

        fragments.add(CompetitiveRecommendFragment())
        fragments.add(CompetitiveManFragment())
        fragments.add(CompetitiveWomanFragment())

        val pagerAdapter = CompetitivePagerAdapter(childFragmentManager,titles,fragments)
        vp_book_competitive.adapter = pagerAdapter
        tab_book_competitive.setupWithViewPager(vp_book_competitive)

        for (i in 0..3){
            val tab = tab_book_competitive.getTabAt(i)
            tab?.setCustomView(R.layout.tab_competitive_item)
            val tabTextView = tab?.customView?.findViewById<TextView>(R.id.tv_tab_name)
            tabTextView?.text = titles[i]
            if (i == 0){
                tabTextView?.setTextSize(TypedValue.COMPLEX_UNIT_SP,20f)
                tabTextView?.setTextColor(Color.parseColor(selectColor))
            }else{
                tabTextView?.setTextSize(TypedValue.COMPLEX_UNIT_SP,16f)
                tabTextView?.setTextColor(Color.parseColor(normalColor))
            }
        }

        tab_book_competitive.addOnTabSelectedListener(object :TabLayout.OnTabSelectedListener{
            override fun onTabReselected(p0: TabLayout.Tab?) {

            }

            override fun onTabUnselected(p0: TabLayout.Tab?) {
                val tab = tab_book_competitive.getTabAt(p0!!.position)
                val tabTextView = tab?.customView?.findViewById<TextView>(R.id.tv_tab_name)
                tabTextView?.setTextSize(TypedValue.COMPLEX_UNIT_SP,16f)
                tabTextView?.setTextColor(Color.parseColor(normalColor))
            }

            override fun onTabSelected(p0: TabLayout.Tab?) {
                val tab = tab_book_competitive.getTabAt(p0!!.position)
                val tabTextView = tab?.customView?.findViewById<TextView>(R.id.tv_tab_name)
                tabTextView?.setTextSize(TypedValue.COMPLEX_UNIT_SP,20f)
                tabTextView?.setTextColor(Color.parseColor(selectColor))
                //选中的tab

            }

        })
    }

    override fun stopLoad() {

    }
}